package com.cloudpark.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloudpark.common.util.ObjectUtil;
import com.cloudpark.model.entity.Region;
import com.cloudpark.model.mapper.RegionMapper;
import com.cloudpark.service.RegionService;

@Service
public class RegionServiceImpl implements RegionService {

	@Autowired
	private RegionMapper regionMapper;
	
	@Override
	public String queryCityOptions() {
		List<Region> list = regionMapper.selectDistinctByCity();
		if (ObjectUtil.isNotBlank(list)) {
			StringBuilder sb = new StringBuilder();
			sb.append("<option value=\"\">-请选择-</option>");
			for (Region region : list) {
				sb.append("<option value=\"").append(region.getCity()).append("\">").append(region.getCity()).append("</option>");
			}
			return sb.toString();
		}
		return null;
	}

	@Override
	public String queryAreaOptions(String city) {
		List<Region> list = regionMapper.selectAreaByCity(city);
		if (ObjectUtil.isNotBlank(list)) {
			StringBuilder sb = new StringBuilder();
			sb.append("<option value=\"\">-请选择-</option>");
			for (Region region : list) {
				sb.append("<option value=\"").append(region.getArea()).append("\">").append(region.getArea()).append("</option>");
			}
			return sb.toString();
		}
		return null;
	}

}
